//
//  ViewController.m
//  一键联IOS
//
//  Created by xufei on 15/12/19.
//  Copyright © 2015年 xufei. All rights reserved.
//

#import "ViewController.h"
#import "HomeVC.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
    [GMDCircleLoader setOnView:self.view withTitle:@"正在验证自动登录" animated:YES];
    //    [HttpsManager requestZiDongDengLuCompletion:^(int errcode, NSString *errmsg)
    //     {
    //         NSString*str=[NSString stringWithFormat:@"%d",errcode];
    //         if ([str isEqualToString:@"0"])
    //         {
    //             //             //             NSUserDefaults*ud=[NSUserDefaults standardUserDefaults];
    //             //             //             [ud setObject:token forKey:@"token"];
    //             //             //             [ud synchronize];
    //             //             //[[NSUserDefaults standardUserDefaults]setObject:token forKey:@"token"];
    //             //             //   SHOW_ALERT(errmsg);
    //             //             HomeVC*vc=[[HomeVC alloc]init];
    //             //             [self.navigationController pushViewController:vc animated:YES];
    //             //   SHOW_ALERT(errmsg);
    //             //return ;
    //                      }
    //         else
    //         {
    //             UIAlertView*alt=[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请重新登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"去登录", nil];
    //             alt.tag=4;
    //             [alt show];
    //         }
    //
    //
    //     }];
    [GMDCircleLoader hideFromView:self.view animated:YES];
    
    NSUserDefaults *fristDown = [NSUserDefaults standardUserDefaults];
    if (![fristDown objectForKey:@"isFrist"]) {
        //
        [self isFristDownload];
        NSLog(@"is frist");
    }else{
        [self goToVC];
        NSLog(@"shouye");
    }
    NSLog(@"%.f\n%.f",WIDE,HEIGHT);
}
-(void)isFristDownload{
    
    _scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDE, HEIGHT)];
    _scroll.contentSize = CGSizeMake(WIDE*3, HEIGHT);
    _scroll.pagingEnabled = YES;
    _scroll.delegate = self;
    _scroll.showsHorizontalScrollIndicator = NO;
    _scroll.showsVerticalScrollIndicator = NO;
    _scroll.backgroundColor = [UIColor blackColor];
    [self.view addSubview:_scroll];
    for (int i = 0; i < 3; i ++) {
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(WIDE * i, 0, WIDE, HEIGHT)];
        image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i+1]];
        image.tag = i+100;
        image.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapimg:)];
        [image addGestureRecognizer:tap];
        [_scroll addSubview:image];
        
        
        //        if (i==2) {
        //            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        //            btn.frame = CGRectMake((WIDE/2.f-80)+WIDE*2, HEIGHT-80, 160, 40);
        //           // btn.backgroundColor = [UIColor cyanColor];
        //            btn.titleLabel.font = [UIFont systemFontOfSize:22.f];
        //            [btn setTitle:@"马上体验" forState:UIControlStateNormal];
        //            [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        //            [btn addTarget:self action:@selector(goToVC) forControlEvents:UIControlEventTouchUpInside];
        //            [self.view addSubview:btn];
        //
        //
        //        }
    }
}
-(void)tapimg:(UIGestureRecognizer *)tap{
    if (tap.view.tag == 102) {
        [self goToVC];
        
    }
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:[NSNumber numberWithBool:YES] forKey:@"isFrist"];
    [userDefaults synchronize];
}
-(void)goToVC{
    //进入首页
    
    [UIView animateWithDuration:0.5 animations:^{
        //动画还是渐消
        _scroll.alpha = 0;
    } completion:^(BOOL finished) {
        if (_scroll.superview) {
            [_scroll removeFromSuperview];
        }
        
        //进首页
        HomeVC *homeVC = [[HomeVC alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:homeVC];
        self.view.window.rootViewController = nav;
        //  [self.navigationController pushViewController:homeVC animated:YES];
        
    }];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
